package com.ljb.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hikvision.vmsnetsdk.RegionInfo;
import com.ljb.haikanglibrary.utils.L;

import java.util.List;

/**
 * Created by ljb on 2017/6/1.
 */

public class RegionAdapter extends BaseAdapter {
    private List<RegionInfo> mRegionInfos;
    private LayoutInflater mInflater;

    public RegionAdapter(Context c, List<RegionInfo> regionInfos) {
        mInflater = LayoutInflater.from(c);
        mRegionInfos = regionInfos;
    }

    @Override
    public int getCount() {
        return mRegionInfos.size();
    }

    @Override
    public RegionInfo getItem(int position) {
        return mRegionInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_region, parent, false);
        }

        TextView tv_region = (TextView) convertView.findViewById(R.id.tv_region);
        tv_region.setText(getItem(position).name);

        if (position == parent.getChildCount()) {
//            if (position == 0) {
//                convertView.setBackgroundColor(Color.BLUE);
//                setForView(convertView);
//            }
            L.e("当前item" + position + "  " + getItem(position).name);
        }
        return convertView;
    }

    private View forView;

    public View getForView() {
        return forView;
    }

    public void setForView(View view) {
        this.forView = view;
    }
}
